/**
 * Created By zhangQ 2018/5/3
 * [$]
 */

import _ from 'lodash'

/**
 * TODO(下划线转为驼峰格式)
 * @param str:::字符串
 * @param firstUppercase:::首字母是否大写，默认小写
 * @auther zhangQ
 * @date 2018/5/1 21:48
 */
export function camelCaseName (str, firstUppercase = false) {
  let resultStr = ''
  for (let i = 0, lenti = str.length; i < lenti; i++) {
    let itemStr = str[i].toLowerCase()
    if (str[i] === '_') {
      i++
      itemStr = str[i].toUpperCase()
    }
    if (i === 0 && firstUppercase) {
      itemStr = itemStr.toUpperCase()
    } else if (i === 0 && !firstUppercase) {
      itemStr = itemStr.toLowerCase()
    }
    resultStr += itemStr
  }
  return resultStr
}

/**
 * 是否存在field字段
 * @param List
 * @param field
 * @returns {boolean}
 */
export function existsField (List, field) {
  let isExists = false
  List.forEach((item) => {
    if (item.name === 'state') {
      isExists = true
    }
  })
  return isExists
}

export function getPrimaryKey (List) {
  return _.find(List, (o) => {
    return o.primaryKey
  })
}
